/** This is a helper class for creating some hashes 
 *  @author Copyright (c) 2005 by chrmac@gmx.de*/

package com.me.client;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/** Class for creating and checking MD5 hashes */
public class MD5Password {

	// private final static char[] HEX = "0123456789abcdef".toCharArray();

	/** Creates a MD5 hash */
	public static String hashPassword(String password) {
		String hashword = null;
		try {
			MessageDigest md5 = MessageDigest.getInstance("MD5");
			md5.update(password.getBytes());
			BigInteger hash = new BigInteger(1, md5.digest());
			hashword = hash.toString(16);

			/*
			 * byte[] bytes = md5.digest(); StringBuffer sb = new StringBuffer(bytes.length * 2); int b;
			 * 
			 * 
			 * for (int i=0; i < bytes.length; i++) { b=bytes[i] & 0xFF; sb.append(HEX[b >>> 4]); sb.append(HEX[b &
			 * 0x0F]); }
			 * 
			 * hashword = sb.toString();
			 */
		} catch (NoSuchAlgorithmException nsae) {
			// ignore
		}
		return hashword;
	}
}
